# ex_huanglx3
# 2021/12/21 15:38
# PyCharm
import re
import requests

def token_users(session,base_url):
    url = "{}/users/login/".format(base_url)
    token_res = session.get(url)
    token = re.findall("name='csrfmiddlewaretoken' value='(.+?)'", token_res.text)
    return token

def users_login(session,base_url,token,username="qaqzz5123@163.com",pwd="a123456"):
    url = "{}/users/login/".format(base_url)
    body = {
        "username": username,
        "password": pwd,
        "csrfmiddlewaretoken": token
    }
    res = session.post(url, data=body)
    return res
if __name__ == '__main__':
    session = requests.Session()
    base_url = "http://49.235.92.12:8200"
    token = token_users(session,base_url)[0]

    login = users_login(session,base_url,
                       token=token)
    print(login.text)